package com.hsy.swu.home.textbook

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.google.gson.annotations.SerializedName

@Entity
class TextbookModel {
    @SerializedName("kcmc")
    @ColumnInfo("courseName")
    var courseName: String = ""

    @SerializedName("jcmc")
    @ColumnInfo("textBookName")
    var textBookName: String = ""

    @SerializedName("isbn")
    @ColumnInfo("isbn")
    var isbn: String = ""

    @SerializedName("jczz")
    @ColumnInfo("author")
    var author: String = ""

    @SerializedName("cbs")
    @ColumnInfo("publisher")
    var publisher: String = ""

    @SerializedName("bbh")
    @ColumnInfo("version")
    var version: String = ""

    @PrimaryKey(autoGenerate = true)
    var id: Int = 0

    override fun toString(): String {
        return "$courseName\t$textBookName\t$isbn\t$author\t$publisher\t$version"
    }

    companion object {
        fun sortTextbookList(textbookList: List<TextbookModel>): List<TextbookModel> {
            val resultList = mutableListOf<TextbookModel>()
            val mutableList = textbookList.toMutableList()
            mutableList.forEach { textbookModel ->
                if (textbookModel.textBookName == "无教材") {
                    resultList.add(textbookModel) // 加在尾
                } else {
                    resultList.add(0, textbookModel) // 加在头
                }
            }
            return resultList
        }
    }
}